package com.example.pkmedical.Activity.weight.tozero;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.pkmedical.APP.MyApp;
import com.example.pkmedical.Base.BaseActivity;
import com.example.pkmedical.DB.WeightData;
import com.example.pkmedical.DB.WeightData_Table;
import com.example.pkmedical.R;
import com.example.pkmedical.Utils.CommandUtil;
import com.example.pkmedical.Utils.SPUtils;
import com.example.pkmedical.Utils.TimeUtils;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.raizlabs.android.dbflow.sql.language.SQLite;
import com.raizlabs.android.dbflow.structure.ModelAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NewUserZreoActivity extends BaseActivity {

    @BindView(R.id.newuserzero_cancle_button)
    Button newuserzeroCancleButton;
    @BindView(R.id.newuserzero_continue_button)
    Button newuserzeroContinueButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newuserzero);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {

    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void showDialog(String... msg) {

    }

    @OnClick({R.id.newuserzero_cancle_button, R.id.newuserzero_continue_button})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.newuserzero_cancle_button:
                finish();
                break;
            case R.id.newuserzero_continue_button:
                CommandUtil.IS_FIRST = true;
                SPUtils.getInstance().put("user_first_weight", "不适用");
                SPUtils.getInstance().put("user_last_weight", "不适用");
                SPUtils.getInstance().put("user_now_weight", "不适用");
                SPUtils.getInstance().put("TOZERO_DATA", "不适用");
//                SPUtils.getInstance().put("NEWUSER_ZERO_DATA", "不适用");
//                SPUtils.getInstance().put("NEWUSER_ZERO_DATA", "不适用");
                SPUtils.getInstance().put("user_difference_weight_all", "0");
                SPUtils.getInstance().put("user_height", "不适用");
                SPUtils.getInstance().put("Initial_time", "不适用");
                SPUtils.getInstance().put("Last_time", "不适用");
                deleteData();
                startActivity(new Intent(MyApp.getAppContext(), NewUserZeroNextActivity.class));
//                overridePendingTransition(R.anim.fade_in, R.anim.fade_out);

                break;
        }
    }
    private void deleteData(){
        List<WeightData> list = SQLite.select().from(WeightData.class).queryList();
        if (0!=list.size()){
            CommandUtil.WEIGHT_DESTORY_ID = list.get(list.size()-1).id;
            if (list.size() == 6) {
                for (int i = 0; i < 6 ; i++) {
                    //方法二 直接删除
                    SQLite.delete(WeightData.class)
                            .where(WeightData_Table.id.eq(CommandUtil.WEIGHT_DESTORY_ID))
                            .execute();
                    CommandUtil.WEIGHT_DESTORY_ID--;
                }
            } else {
                int size = list.size();
                for (int i = 0; i < size; i++) {
                    //方法二 直接删除
                    SQLite.delete(WeightData.class)
                            .where(WeightData_Table.id.eq(CommandUtil.WEIGHT_DESTORY_ID))
                            .execute();
                    CommandUtil.WEIGHT_DESTORY_ID--;
                }
            }
        }

    }
}
